/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aaron.platform.view;

import com.aaron.platform.entity.ItscDomainInfo;
import com.aaron.platform.exceptions.UserSessionException;
import com.aaron.platform.service.IDomainService;
import com.aaron.platform.service.IUserService;
import com.aaron.platform.service.UserSession;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.model.SelectItem;
import javax.servlet.http.HttpSession;

/**
 *
 * @author aaronbamboo
 */
public class ItscListBean {
    
    private IDomainService domainService;
    
    private List<SelectItem> userDomainList;

    public void setDomainService(IDomainService domainService) {
        this.domainService = domainService;
    }
    
    public List<SelectItem> getUserDomainList() {
        
        if (userDomainList != null) {
            return userDomainList;
        }
        
        // 获取用户权限下的所有域
        userDomainList = new ArrayList<SelectItem>();
        UserSession userSession = null;
        try {
            HttpSession httpSession = FacesUtil.getClientSession();
            userSession = (UserSession) httpSession.getAttribute("user");
        } catch (UserSessionException ex) {
            Logger.getLogger(ItscListBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        ItscDomainInfo domainInfo = userSession.getUserInfo().getDomainInfo();
        userDomainList.add(new SelectItem(domainInfo.getDomainId(), domainInfo.getDomainName()));
        List<ItscDomainInfo> subDomains = domainService.findSubDomains(domainInfo.getDomainId());
        if (subDomains != null) {
            for (ItscDomainInfo subDomain : subDomains) {
                userDomainList.add(new SelectItem(subDomain.getDomainId(), subDomain.getDomainName()));
            }
        }
        return userDomainList;
    }
    
}
